<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('新增优惠卷模板')"/>
    <th:block th:include="include :: datetimepicker-css"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-discount-add">
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">优惠卷名称：</label>
            <div class="col-sm-8">
                <input name="name" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">剩余数量：</label>
            <div class="col-sm-8">
                <input name="num" class="form-control" type="text" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">最大领取次数：</label>
            <div class="col-sm-8">
                <input name="maxNumber" class="form-control" type="text" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">有效期模式：</label>
            <div class="col-sm-8">
                <select name="dateType" class="form-control m-b" th:with="type=${@dict.getType('dd_discount')}">
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}">
                    </option>
                </select>
            </div>
        </div>
        <div id="dateType">
            <div class="form-group">
                <label class="col-sm-3 control-label">有效期起始日：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        <input name="beginTime" class="form-control" placeholder="yyyy-MM-dd" type="text">
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">有效期结束日：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        <input name="endTime" class="form-control" placeholder="yyyy-MM-dd" type="text">
                    </div>
                </div>
            </div>

        </div>
        <div class="form-group" id="dateNumber">
            <label class="col-sm-3 control-label">领取后有效期天数：</label>
            <div class="col-sm-8">
                <input name="dateNumber" class="form-control" type="text">
            </div>
        </div>
<!--        <div class="form-group">-->
<!--            <label class="col-sm-3 control-label">领取条件字段：</label>-->
<!--            <div class="col-sm-8">-->
<!--                <select name="conditionField" th:with="type=${@dict.getType('dd_discount')}">-->
<!--                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}"-->
<!--                            th:value="${dict.dictValue}"></option>-->
<!--                </select>-->
<!--            </div>-->

<!--        </div>-->
<!--        <div class="form-group">-->
<!--            <label class="col-sm-3 control-label">条件限制：</label>-->
<!--            <div class="col-sm-8">-->
<!--                <input name="conditionalit" class="form-control" type="text">-->
<!--            </div>-->
<!--        </div>-->
        <div class="form-group">
            <label class="col-sm-3 control-label">优惠额度：</label>
            <div class="col-sm-8 input-group">
                <input name="quota" class="form-control" type="text">
                <span class="input-group-addon">%</span>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">备注：</label>
            <div class="col-sm-8">
                <input name="remake" class="form-control" type="text">
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: datetimepicker-js"/>
<script type="text/javascript">
    var prefix = ctx + "system/discount"
    $("#form-discount-add").validate({
        focusCleanup: true
    });
    $("div[id='dateType']").show();
    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/add", $('#form-discount-add').serialize());
        }
    }

    $("input[name='beginTime']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });

    $("input[name='endTime']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });
    $("select[name='dateType']").change(function () {
        console.log($("select[name='dateType']").val());
        if ($("select[name='dateType']").val() == "0"){
            $("div[id='dateNumber']").hide();
            $("div[id='dateType']").show();
        }else if($("select[name='dateType']").val() == "1"){
            $("div[id='dateType']").hide();
            $("div[id='dateNumber']").show();
        }
    });
    console.log($("select[name='dateType']"));
</script>
</body>
</html>